package com.datastructure.search.binarysearch;

public class CompareVersion {

    public static void main(String[] args) {
        System.out.println(compare("1.1","2.1"));
    }

    public static int compare (String version1, String version2) {
        // write code here
        int result = 0;
        int maxLength;
        String[] split = version1.split("\\.");
        String[] split1 = version2.split("\\.");
        maxLength = Math.max(split.length, split1.length);
        int[] data = new int[maxLength];
        int[] data1 = new int[maxLength];
        for (int i = 0; i < split.length; i++) {
            data[i]=Integer.parseInt(split[i]);
        }
        for (int i = 0; i < split1.length; i++) {
            data1[i] = Integer.parseInt(split1[i]);
        }
        for (int i = 0; i < maxLength; i++) {
            if(data[i]<data1[i]){
                result=-1;
                break;
            }else if(data[i]>data1[i]) {
                result=1;
                break;
            }
        }
        return result;
    }
}
